using IM.Easy.Infrastructure.Query;
using Microsoft.AspNetCore.Mvc;
using IM.Easy.SystemServices.Dtos;
using IM.Easy.SystemServices.IServices;
using IM.Easy.Entity.System;

namespace IM.Easy.Api.Controllers.System
{
    /// <summary>
    /// SysNotificationController 控制器
    /// </summary>
    [Route("system/notification")]
    public class NotificationController : ControllerBase
    {
        private readonly INotificationService _service;

        /// <summary>
        /// 构造函数，注入服务
        /// </summary>
        /// <param name="service">服务接口</param>
        public NotificationController(INotificationService service)
        {
            _service = service;
        }

        /// <summary>
        /// 获取所有SysNotification对象
        /// </summary>
        /// <returns>返回SysNotification列表</returns>
        [HttpGet]
        public PageResponse<SysNotification> GetList([FromQuery] SysNotificationQueryDto query)
        {
            return _service.GetPageList(query);
        }

        /// <summary>
        /// 根据ID获取SysNotification对象
        /// </summary>
        /// <param name="id">对象的ID</param>
        /// <returns>返回指定的SysNotification对象</returns>
        [HttpGet("{id}")]
        public SysNotification GetById([FromRoute] long id)
        {
            var result = _service.GetById(id);
            return result ?? throw new KeyNotFoundException($"未找到ID为 {id} 的SysNotification对象。");
        }

        /// <summary>
        /// 创建新的SysNotification对象
        /// </summary>
        /// <param name="entity">要创建的SysNotification对象</param>
        /// <returns>返回创建后的SysNotification对象</returns>
        [HttpPost]
        public SysNotification Create([FromBody] SysNotification entity)
        {
            _service.Create(entity);
            return entity; // 直接返回创建的实体
        }

        /// <summary>
        /// 更新现有的SysNotification对象
        /// </summary>
        /// <param name="id">对象的ID</param>
        /// <param name="entity">更新后的SysNotification对象</param>
        [HttpPut]
        public void Update([FromBody] SysNotification entity)
        {
            _service.Update(entity);
        }

        /// <summary>
        /// 批量删除SysNotification对象
        /// </summary>
        /// <param name="ids">对象的IDS</param>
        [HttpDelete]
        public void Delete([FromBody] long[] ids)
        {
            _service.Delete(ids);
        }

        /// <summary>
        /// 单个删除SysNotification对象
        /// </summary>
        /// <param name="id">对象的ID</param>
        [HttpDelete("{id}")]
        public void Delete([FromRoute] long id)
        {
            _service.Delete(id);
        }
    }
}
